package org.sxp.common.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 龙勇
 * @date 2020/12/23
 */
@Data
public class PageResult<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    private int pageNum;
    private int pageSize;
    private int size;
    private int startRow;
    private int endRow;
    private int pages;
    private int recordCounts;
    private boolean isFirstPage = false;
    private boolean isLastPage = false;
    private List<T> Data;

    public PageResult() {
        this.Data = new ArrayList();
    }

    public PageResult(IPage<T> page) {
        this.setData(page.getRecords());//List数据
        this.setRecordCounts((int)page.getTotal());//记录条数
        this.setPageSize((int)page.getSize());//每页大小
        this.setPageNum((int)page.getCurrent());//当前多少页
        this.setPages((int)page.getPages());//总分页大小
        this.setFirstPage(page.getCurrent() == 1);
        this.setLastPage(page.getCurrent() == page.getPages());
    }

    public PageResult(int recordCounts, int pages, int pageSize, int pageNum, List<T> data) {
        this.recordCounts = recordCounts;
        this.pages = pages;
        this.pageSize = pageSize;
        this.pageNum = pageNum;
        this.Data = data;
    }
}